Xi-Language Reference: Geometrical Transformations

    • convol (performs a general MxN convolution)
    • crop (crops an image)
    • fft_image_filter (filters an image in the frequency domain)
    • flip (performs one or more flip operations)
    • hist_equal (computes a histogram-equalized vector )
    • image_pad (adds extra borders of the sizes specified)
    • image_resize (change the size of an image)
    • rotate (rotates an image by some angle)
    • shear (shears an image by some angle)
    • smooth (smoothes out an image)

    convol (performs a general MxN convolution)

    Parameters

              convol ( image, kernel, flag = 0 )
    
              Types: image                  char[]
                     kernel                 double[]
                     flag                   int
    

    Return

              char[]  (contains the RGB or colormap based image)
    

    Description

    The function convol performs a general MxN convolution on a RGB image or a colormap based image. Convolution means replacing each pixel with a weighted average of the nearby pixels. The weights and the area to average are determined by the convolution matrix kernel. Use the flag \rescale to enable rescaling of the image.

    Example

    >kernel=double({ {1,2,1},{2,4,2},{1,2,1} });
    >kernel/=total(kernel);                    
    >co=convol(colorBased, kernel, \rescale);
    

    See also

    smooth

    crop (crops an image)

    Parameters

              crop ( image, white = 0, black = 1, black = 0, top = 0, 
                     bottom = 0, left = 0, right = 0   )
    
              Types: image                  char[]
                     white                  int
                     black                  int
                     black                  int
                     top                    int
                     bottom                 int
                     left                   int
                     right                  int
    

    Return

              char[]  (contains the image, RGB color system or colormap based image)
    

    Description

    The function crop removes edges that are the background color. It guesses what the background color might be. You can override the default with the white and black flags. The options left, right, top and bottom restrict cropping to the sides specified. The default is to crop all sides of the image.

    Example

    >image=carr(10,10,3);
    >image[3:8,3:8,*]=255;
    >new=crop(image);
    >print(size(new))
    <intarr>
      5   3 108   6   6   3 
    

    See also

    image_pad

    Reference

    This function is based on the file pnmcrop.c of the netpbm tools.
     **
     ** Copyright (C) 1988 by Jef Poskanzer.
     **
    

    fft_image_filter (filters an image in the frequency domain)

    Parameters

              fft_image_filter ( image, radius )
    
              Types: image                  char[]
                     radius                 int
    

    Return

              char[]  (contains the filtered image)
    

    Description

    The function fft_image_filter performs an ideal low pass filter with cutoff frequency radius.

    See also

    fft, rev_fft

    flip (performs one or more flip operations)

    Parameters

              flip ( image, r90 = 0, r180 = 0, r270 = 0, topbottom = 0, 
                     leftright = 0 )
    
              Types: image                  char[]
                     r90                    int
                     r180                   int
                     r270                   int
                     topbottom              int
                     leftright              int
    

    Return

              char[]  (contains the image, RGB color system or colormap based image)
    

    Description

    The function flip performs one or more flip operations. image can be a two dimensional array [rows, cols]for colormap based images or a three dimensional array [rows, columns, 3] for images of the RGB color system. The flip operations available are: left for right (\leftright) and top for bottom (\topbottom). In addition some concatenations are available: rotation 90 degrees (\r90), rotation 180 degrees (\r180) and rotation 270 degrees (\r270).

    Example

    >image=cincarr(10,10,3);
    >new=flip(image,\topbottom);
    

    hist_equal (computes a histogram-equalized vector )

    Parameters

              hist_equal ( image )
    
              Types: image                  char[]
    

    Return

              char[]  (contains the histogram-equalized image or vector)
    

    Description

    The function hist_equal equalize the histogram of an image or vector. This function is useful to enhanced the contrast of a grayscale image.

    Example

     >a={ 10,15,12,11,17,18,16,16,15 }
     >print(hist_equal(a));
     <chrarr>
     28 113  84  56 226 254 169 169 113
    

    See also

    histogram

    image_pad (adds extra borders of the sizes specified)

    Parameters

              image_pad ( image, top = 0, bottom = 0, left = 0, right = 0, 
                          color = {0,0,0}, value = 0 )
    
              Types: image                  char[]
                     top                    int
                     bottom                 int
                     left                   int
                     right                  int
                     color                  char[]
                     value                  char
    

    Return

              char[]  (contains the image, RGB color system or colormap based image)
    

    Description

    The function image_pad adds extra borders of the specified sizes and color. image can be a two dimensional array [rows, columns]for colormap based images or a three dimensional array [rows, columns, 3] for images of the RGB color system. The parameters top, bottom, left and right control the width of the border sides. In case of colormap based images the border color is set with the parameter value. For RGB images the parameter color determines the color of the border.

    Example

    >image=carr(3,3);
    >new1=image_pad(image,\bottom=1,\value=42);
    >image=cincarr(5,5,3);
    >new2=image_pad(image,\top=3,\left=1,\color={42,7, 8};
    

    See also

    crop

    image_resize (change the size of an image)

    Parameters

              image_resize ( image, rows, cols, sample = 1, linear = 0 )
    
              Types: image                  char[]
                     rows                   int
                     cols                   int
                     sample                 int
                     linear                 int
    

    Return

              char[]  (contains the image resized to the given dimensions, RGB color system or colormap based image)
    

    Description

    The function image_resize is a special version of the function resize to accelerate magnifying or shrinking of an image. image can be a two dimensional array [rows, columns]for colormap based images or a three dimensional array [rows, columns, 3] for images of the RGB color system. If the flag sample is set image_resize uses nearest neigbbourhood sampling. Set linear to advice image_resize to use the multilinear interpolation method. If neither sample nor linear are given image_resize uses nearst neigbbourhood sampling.

    Example

    >image=carr(3,3);
    >new1=image_resize(image,50,50,\linear);
    

    rotate (rotates an image by some angle)

    Parameters

              rotate ( image, phi, noantialiase = 0 )
    
              Types: image                  char[]
                     phi                    double
                     noantialiase           int
    

    Return

              char[]  (contains the image, RGB color system or colormap based image)
    

    Description

    The function rotate performs a rotation of the image by the specified angle phi. image can be a two dimensional array [rows, cols]for colormap based images or a three dimensional array [rows, columns, 3] for images of the RGB color system. The angle phi is measured counter-clockwise in degrees. The angle should not get too close to 90 or -90, or else the resulting image will be unreasonably wide. The rotation algorithm is Alan Paeth's three-shear method. Each shear is implemented by looping over the source pixels and distributing fractions to each of the destination pixels. This has an "anti-aliasing" effect - it avoids jagged edges and similar artifacts. However, it also means that the original colors or gray levels in the image are modified. If you need to keep precisely the same set of colors, you can use the noantialiase flag.

    Example

    >image=cincarr(10,10,3);
    >new1=rotate(image, 73);
    >image=cincarr(5,5);
    >new2=rotate(image,54,\noantialiase);
    

    See also

    shear

    Reference

    This function is based on the file pnmrotate.c of the netpbm tools.
     **
     ** Copyright (C) 1989, 1991 by Jef Poskanzer.
     **
    

    shear (shears an image by some angle)

    Parameters

              shear ( image, phi, noantialiase )
    
              Types: image                  char[]
                     phi                    double
                     noantialiase           int
    

    Return

              char[]  (contains the image, RGB color system or colormap based image)
    

    Description

    The function shear shears an image by the specified angle phi. image can be a two dimensional array [rows, columns]for colormap based images or a three dimensional array [rows, columns, 3] for images of the RGB color system. The angle is measured in degrees. The angle should not get too close to 90 or -90, or else the resulting image will be unreasonably wide. The shearing is implemented by looping over the source pixels and distributing fractions to each of the destination pixels. This has an "anti-aliasing" effect - it avoids jagged edges and similar artifacts. However, it also means that the original colors or gray levels in the image are modified. If you need to keep precisely the same set of colors, you can use the noantialiase flag.

    Example

    >image=cincarr(10,10,3);
    >new1=shear(image, 73);
    >image=cincarr(5,5);
    >new2=shear(image,54,\noantialiase);
    

    See also

    rotate

    Reference

    This function is based on the file pnmshear.c of the netpbm tools.
     **
     ** Copyright (C) 1989, 1991 by Jef Poskanzer.
     **
    

    smooth (smoothes out an image)

    Parameters

              smooth ( image, range = 3, rescale = 0 )
    
              Types: image                  char[]
                     range                  int
                     rescale                int
    

    Return

              char[]  (contains the image, RGB color system or colormap based image)
    

    Description

    The function smooth smoothes out an image by replacing each pixel with the average of its range*range immediate neighbors. Hence range is the width of the smoothing window (should be an odd number). Use the rescale flag to rescale the image.

    Example

    >image=cincarr(10,10,3);
    >new=smooth(image,5,\rescale);
    

    See also

    convol
    © 1995 by Bodo Junglas, Klaus Spanderen and Fabian Weis
    - Last revised: Wed Jun 19 16:58:32 1996